package com.nbsaas.boot.ai.controller;

import com.nbsaas.boot.ai.ext.apis.AiSessionExtApi;
import com.nbsaas.boot.rest.annotations.*;
import com.nbsaas.boot.rest.response.ListResponse;
import com.nbsaas.boot.rest.response.PageResponse;
import com.nbsaas.boot.rest.response.ResponseObject;
import com.nbsaas.boot.ai.api.domain.request.AiSessionRequest;
import com.nbsaas.boot.ai.api.domain.request.AiSessionSearch;
import com.nbsaas.boot.ai.api.domain.response.AiSessionResponse;
import com.nbsaas.boot.ai.api.domain.simple.AiSessionSimple;
import com.nbsaas.boot.ai.api.apis.AiSessionApi;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestBody;
import jakarta.annotation.Resource;

/**
 * AI对话会话控制器
 */
@RequiresAuthentication
@RestController
@RequestMapping("/aiSession")
public class AiSessionController {


    @Resource
    private AiSessionApi aiSessionApi;

    @Resource
    private AiSessionExtApi aiSessionExtApi;

    /**
     * 搜索数据
     *
     * @param request
     * @return
     */
    @SearchData
    @RequiresPermissions("aiSession:search")
    @PostMapping("/search")
    public PageResponse<AiSessionSimple> search(@RequestBody AiSessionSearch request) {
        return aiSessionApi.search(request);
    }

    /**
     * 列表数据
     *
     * @param request
     * @return
     */
    @SearchData
    @RequiresPermissions("aiSession:list")
    @PostMapping("/list")
    public ListResponse<AiSessionSimple> list(@RequestBody AiSessionSearch request) {
        return aiSessionApi.list(request);
    }

    /**
     * 添加数据
     *
     * @param request
     * @return
     */
    @CreateData
    @PostMapping("/create")
    public ResponseObject<AiSessionResponse> create(@RequestBody @Validated(AddOperator.class) AiSessionRequest request) {
        return aiSessionExtApi.create(request);
    }

    /**
     * 修改数据
     *
     * @param request
     * @return
     */
    @RequiresPermissions("aiSession:update")
    @UpdateData
    @PostMapping("/update")
    public ResponseObject<AiSessionResponse> update(@RequestBody @Validated(UpdateOperator.class) AiSessionRequest request) {
        return aiSessionApi.update(request);
    }

    /**
     * 删除数据
     *
     * @param request
     * @return
     */
    @SearchData
    @RequiresPermissions("aiSession:delete")
    @PostMapping("/delete")
    public ResponseObject<?> delete(@RequestBody @Validated(DeleteOperator.class) AiSessionRequest request) {
        return aiSessionApi.delete(request);
    }

    /**
     * 查看数据
     *
     * @param request
     * @return
     */
    @SearchData
    @RequiresPermissions("aiSession:view")
    @PostMapping("/view")
    public ResponseObject<AiSessionResponse> view(@RequestBody @Validated(ViewOperator.class) AiSessionRequest request) {
        return aiSessionApi.view(request);
    }
}